package com.shiyingzi.product.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.shiyingzi.common.EntityUtils;
import com.shiyingzi.common.PageUtils;
import com.shiyingzi.common.PageableData;
import com.shiyingzi.common.ResponseData;
import com.shiyingzi.product.dao.AppABasicInformationDao;
import com.shiyingzi.product.dao.AppBOccupationalDao;
import com.shiyingzi.product.dao.AppCIncomeAndLiabilityDao;
import com.shiyingzi.product.dao.AppDContactInformationDao;
import com.shiyingzi.product.dao.AppEBorrowerInformationDao;
import com.shiyingzi.product.dao.AppFHousePropertyDao;
import com.shiyingzi.product.dao.AppGWorkInformationDao;
import com.shiyingzi.product.dao.AppHPolicyInformationDao;
import com.shiyingzi.product.dao.AppIImpPathDao;
import com.shiyingzi.product.model.AppABasicInformation;
import com.shiyingzi.product.model.AppBOccupational;
import com.shiyingzi.product.model.AppCIncomeAndLiability;
import com.shiyingzi.product.model.AppDContactInformation;
import com.shiyingzi.product.model.AppEBorrowerInformation;
import com.shiyingzi.product.model.AppFHouseProperty;
import com.shiyingzi.product.model.AppGWorkInformation;
import com.shiyingzi.product.model.AppHPolicyInformation;
import com.shiyingzi.product.model.AppIImpPath;
import com.shiyingzi.product.service.AppABasicInformationService;

@Service(AppABasicInformationService.BEAN_ID)
public class AppABasicInformationServiceImpl extends ServiceImpl<AppABasicInformationDao, AppABasicInformation> implements AppABasicInformationService{
	@Autowired
	private AppABasicInformationDao appABasicInformationDao;
	
	@Autowired
	private AppBOccupationalDao appBOccupationalDao;
	
	@Autowired
	private AppCIncomeAndLiabilityDao appCIncomeAndLiabilityDao;
	
	@Autowired
	private AppDContactInformationDao appDContactInformationDao;
	
	@Autowired
	private AppEBorrowerInformationDao appEBorrowerInformationDao;
	
	@Autowired
	private AppFHousePropertyDao appFHousePropertyDao;
	@Autowired
	private AppGWorkInformationDao appGWorkInformationDao;
	@Autowired
	private AppHPolicyInformationDao appHPolicyInformationDao;
	@Autowired
	private AppIImpPathDao appIImpPathDao;

	@Autowired
	private HttpSession session;
	
	@Override
	public ResponseData addAppABasicInformation(AppABasicInformation code) {
		try{
			code.setDeleteFlag("N");
			return new ResponseData(true,"true",insert(code));
		}catch(Exception e){
			return new ResponseData(false,"false");
		}
	}
	@Override
	public PageableData<AppABasicInformation> queryAppABasicInformationList(int page, int limit, String userName) {
		Page<AppABasicInformation> mypage = new Page<AppABasicInformation>();
		mypage.setCurrent(page);
		mypage.setSize(limit);
		AppABasicInformation ac =new AppABasicInformation();
		if(!StringUtils.isEmpty(userName)){
			ac.setName(userName);
		}
		return PageUtils.tableDataDto(selectPage(mypage,new EntityWrapper<AppABasicInformation>(ac).orderBy("createTime")));
	}
	@Override
	public AppABasicInformation getProductById(Integer id) {
		AppABasicInformation role = appABasicInformationDao.selectById(id);
		return role;
	}
	@Override
	public ResponseData addProduct(AppABasicInformation code,AppBOccupational code2
			,AppCIncomeAndLiability code3,ArrayList<AppDContactInformation> code4
			,AppEBorrowerInformation code5,AppFHouseProperty code6
			,AppGWorkInformation code7 ,AppHPolicyInformation code8
			,ArrayList<AppIImpPath> filea,ArrayList<AppIImpPath> fileb,ArrayList<AppIImpPath> filec
			,ArrayList<AppIImpPath> filed,ArrayList<AppIImpPath> filee,ArrayList<AppIImpPath> filef
			,ArrayList<AppIImpPath> fileg,ArrayList<AppIImpPath> fileh,ArrayList<AppIImpPath> filei) {
		try{
			code.setDeleteFlag("N");
			EntityUtils.initEntity(code, session);
//			AppABasicInformation flag=appABasicInformationDao.insert(code);
			insert(code);
			if(code==null){
				return new ResponseData(false,"false");
			}else{
				code2.setUnitName(code.getAbo().getUnitName());
				code2.setEntryTime(code.getAbo().getEntryTime());
				code2.setOfficePhone(code.getAbo().getOfficePhone());
				code2.setUnitAddressArea(code.getAbo().getUnitAddressArea());
				code2.setIndustryType(code.getAbo().getIndustryType());
				code2.setDepartment(code.getAbo().getDepartment());
				code2.setMonthlyPayday(code.getAbo().getMonthlyPayday());
				code2.setDeleteFlag("N");
				code2.setAppAId(code.getId());
				EntityUtils.initEntity(code2, session);
//				appBOccupationalDao.insert(code2);
				appBOccupationalDao.insert(code2);
				if(code2==null){
					deleteById(code.getId());
					return new ResponseData(false,"false");
				}
				code3.setMonthlyIncome(code.getAcial().getMonthlyIncome());
				code3.setOtherMonthlyIncome(code.getAcial().getOtherMonthlyIncome());
				code3.setSupportNumber(code.getAcial().getSupportNumber());
				code3.setFamilyDebt(code.getAcial().getFamilyDebt());
				code3.setHousingLoan(code.getAcial().getHousingLoan());
				code3.setFixedExpenditure(code.getAcial().getFixedExpenditure());
				code3.setOrganizationName(code.getAcial().getOrganizationName());
				code3.setAmountOfMoney(code.getAcial().getAmountOfMoney());
				code3.setDeleteFlag("N");
				code3.setAppAId(code.getId());
				EntityUtils.initEntity(code3, session);
				appCIncomeAndLiabilityDao.insert(code3);
				if(code3.getId()==null){
					appABasicInformationDao.deleteById(code.getId());
					appBOccupationalDao.deleteById(code2.getId());
					return new ResponseData(false,"false");
				}
				List<AppDContactInformation> adci=code.getAdci();
				for(AppDContactInformation adci2:adci){
					adci2.setDeleteFlag("N");
					adci2.setAppAId(code.getId());
					EntityUtils.initEntity(adci2, session);
					appDContactInformationDao.insert(adci2);
					if(adci2==null){
						appABasicInformationDao.deleteById(code.getId());
						appBOccupationalDao.deleteById(code2.getId());
						appCIncomeAndLiabilityDao.deleteById(code3.getId());
						return new ResponseData(false,"false");
					}
				}
				if(code.getWhetherOrNot().equals("2")){
					code5.setBoName(code.getAebi().getBoName());
					code5.setUnitName(code.getAebi().getUnitName());
					code5.setEntryTime(code.getAebi().getEntryTime());
					code5.setOfficePhone(code.getAebi().getOfficePhone());
					code5.seteAddressArea(code.getAebi().geteAddressArea());
					code5.setDeleteFlag("N");
					code5.setAppAId(code.getId());
					EntityUtils.initEntity(code5, session);
					appEBorrowerInformationDao.insert(code5);
					if(code5==null){
						appABasicInformationDao.deleteById(code.getId());
						appBOccupationalDao.deleteById(code2.getId());
						appCIncomeAndLiabilityDao.deleteById(code3.getId());
						appDContactInformationDao.deleteById(code.getId());
						return new ResponseData(false,"false");
					}
				}
				if(code.getProductType().equals("1") || code.getProductType().equals("3")){
					code6.setReimbursementAmount(code.getAfhp().getReimbursementAmount());
					code6.setPurchaseTimeYear(code.getAfhp().getPurchaseTimeYear());
					code6.setPurchaseTimeMonth(code.getAfhp().getPurchaseTimeMonth());
					code6.setPurchasePrice(code.getAfhp().getPurchasePrice());
					code6.setArea(code.getAfhp().getArea());
					code6.setDeleteFlag("N");
					code6.setAppAId(code.getId());
					EntityUtils.initEntity(code6, session);
					appFHousePropertyDao.insert(code6);
					if(code6==null){
						appABasicInformationDao.deleteById(code.getId());
						appBOccupationalDao.deleteById(code2.getId());
						appCIncomeAndLiabilityDao.deleteById(code3.getId());
						appDContactInformationDao.deleteById(code.getId());
						if(code.getWhetherOrNot().equals("2")){
							appEBorrowerInformationDao.deleteById(code5.getId());
						}
						return new ResponseData(false,"false");
					}
				}
				if(code.getProductType().equals("2") || code.getProductType().equals("5")){
					code7.setAcDeposit(code.getAgwi().getAcDeposit());
					code7.setAcDepositLength(code.getAgwi().getAcDepositLength());
					code7.setAcFundAccount(code.getAgwi().getAcFundAccount());
					code7.setSoDeposit(code.getAgwi().getSoDeposit());
					code7.setAcDepositLength(code.getAgwi().getAcDepositLength());
					code7.setDeleteFlag("N");
					code7.setAppAId(code.getId());
					EntityUtils.initEntity(code7, session);
					appGWorkInformationDao.insert(code7);
					if(code7==null){
						appABasicInformationDao.deleteById(code.getId());
						appBOccupationalDao.deleteById(code2.getId());
						appCIncomeAndLiabilityDao.deleteById(code3.getId());
						appDContactInformationDao.deleteById(code.getId());
						if(code.getWhetherOrNot().equals("2")){
							appEBorrowerInformationDao.deleteById(code5.getId());
						}
						return new ResponseData(false,"false");
					}
				}
				if(code.getProductType().equals("4")){
					code8.setInsuranceCompany(code.getAhpi().getInsuranceCompany());
					code8.setEffectiveDate(code.getAhpi().getEffectiveDate());
					code8.setYears(code.getAhpi().getYears());
					code8.setRegularPremium(code.getAhpi().getRegularPremium());
					code8.setTotalAmountInsured(code.getAhpi().getTotalAmountInsured());
					code8.setDeleteFlag("N");
					code8.setAppAId(code.getId());
					EntityUtils.initEntity(code8, session);
					appHPolicyInformationDao.insert(code8);
					if(code8==null){
						appABasicInformationDao.deleteById(code.getId());
						appBOccupationalDao.deleteById(code2.getId());
						appCIncomeAndLiabilityDao.deleteById(code3.getId());
						appDContactInformationDao.deleteById(code.getId());
						if(code.getWhetherOrNot().equals("2")){
							appEBorrowerInformationDao.deleteById(code5.getId());
						}
						return new ResponseData(false,"false");
					}
				}
				
//				if(filea.length>0){
//					for(int i=0;i<filea.length;i++){
//						if(filea[i]!=null &&  !filea[i].isEmpty()){
//							AppIImpPath aip=new AppIImpPath();
//							Map<String, Object> map1 = new HashMap<String, Object>();
//							String insertFilePath=Constants.a+Constants.IMG_ROOT+Constants.a+Constants.IMG_PATH;
//							map1=FileUtil.uploadimg(filea[i],null,insertFilePath);
//							if(map1.get("flag").equals(false)){
//								appABasicInformationDao.deleteById(code.getId());
//								appBOccupationalDao.deleteById(code2.getId());
//								appCIncomeAndLiabilityDao.deleteById(code3.getId());
//								appDContactInformationDao.deleteById(code.getId());
//								if(code.getWhetherOrNot().equals("2")){
//									appEBorrowerInformationDao.deleteById(code5.getId());
//								}
//								return new ResponseData(false,"false");
//							}else{
//								aip.setAppAId(code.getId());
//								aip.setImpType("1");
//								aip.setImpPath((String)map1.get("urldatepath"));
//								EntityUtils.initEntity(aip, session);
//								AppIImpPath flag5=appIImpPathDao.insert(aip);
//								if(flag5==null){
//									appABasicInformationDao.deleteById(code.getId());
//									appBOccupationalDao.deleteById(code2.getId());
//									appCIncomeAndLiabilityDao.deleteById(code3.getId());
//									appDContactInformationDao.deleteById(code.getId());
//									if(code.getWhetherOrNot().equals("2")){
//										appEBorrowerInformationDao.deleteById(code5.getId());
//									}
//									return new ResponseData(false,"false");
//								}
//							}
//						}
//					}
//				}
				if(code.getFilea() !=null && code.getFilea().size()>0){
					for(AppIImpPath aip:code.getFilea()){
						aip.setAppAId(code.getId());
						aip.setImpType("1");
						EntityUtils.initEntity(aip, session);
						appIImpPathDao.insert(aip);
						if(aip==null){
							appABasicInformationDao.deleteById(code.getId());
							appBOccupationalDao.deleteById(code2.getId());
							appCIncomeAndLiabilityDao.deleteById(code3.getId());
							appDContactInformationDao.deleteById(code.getId());
							if(code.getWhetherOrNot().equals("2")){
								appEBorrowerInformationDao.deleteById(code5.getId());
							}
							return new ResponseData(false,"false");
						}
					}
				}
				if(code.getFileb() !=null && code.getFileb().size()>0){
					for(AppIImpPath aip:code.getFileb()){
						aip.setAppAId(code.getId());
						aip.setImpType("1");
						EntityUtils.initEntity(aip, session);
						appIImpPathDao.insert(aip);
						if(aip==null){
							appABasicInformationDao.deleteById(code.getId());
							appBOccupationalDao.deleteById(code2.getId());
							appCIncomeAndLiabilityDao.deleteById(code3.getId());
							appDContactInformationDao.deleteById(code.getId());
							if(code.getWhetherOrNot().equals("2")){
								appEBorrowerInformationDao.deleteById(code5.getId());
							}
							return new ResponseData(false,"false");
						}
					}
				}
				if(code.getFilec() !=null && code.getFilec().size()>0){
					for(AppIImpPath aip:code.getFilec()){
						aip.setAppAId(code.getId());
						aip.setImpType("1");
						EntityUtils.initEntity(aip, session);
						appIImpPathDao.insert(aip);
						if(aip==null){
							appABasicInformationDao.deleteById(code.getId());
							appBOccupationalDao.deleteById(code2.getId());
							appCIncomeAndLiabilityDao.deleteById(code3.getId());
							appDContactInformationDao.deleteById(code.getId());
							if(code.getWhetherOrNot().equals("2")){
								appEBorrowerInformationDao.deleteById(code5.getId());
							}
							return new ResponseData(false,"false");
						}
					}
				}
				if(code.getFiled() !=null && code.getFiled().size()>0){
					for(AppIImpPath aip:code.getFiled()){
						aip.setAppAId(code.getId());
						aip.setImpType("1");
						EntityUtils.initEntity(aip, session);
						appIImpPathDao.insert(aip);
						if(aip==null){
							appABasicInformationDao.deleteById(code.getId());
							appBOccupationalDao.deleteById(code2.getId());
							appCIncomeAndLiabilityDao.deleteById(code3.getId());
							appDContactInformationDao.deleteById(code.getId());
							if(code.getWhetherOrNot().equals("2")){
								appEBorrowerInformationDao.deleteById(code5.getId());
							}
							return new ResponseData(false,"false");
						}
					}
				}
				if(code.getFilee() !=null && code.getFilee().size()>0){
					for(AppIImpPath aip:code.getFilee()){
						aip.setAppAId(code.getId());
						aip.setImpType("1");
						EntityUtils.initEntity(aip, session);
						appIImpPathDao.insert(aip);
						if(aip==null){
							appABasicInformationDao.deleteById(code.getId());
							appBOccupationalDao.deleteById(code2.getId());
							appCIncomeAndLiabilityDao.deleteById(code3.getId());
							appDContactInformationDao.deleteById(code.getId());
							if(code.getWhetherOrNot().equals("2")){
								appEBorrowerInformationDao.deleteById(code5.getId());
							}
							return new ResponseData(false,"false");
						}
					}
				}
				if(code.getFilef() !=null && code.getFilef().size()>0){
					for(AppIImpPath aip:code.getFilef()){
						aip.setAppAId(code.getId());
						aip.setImpType("1");
						EntityUtils.initEntity(aip, session);
						appIImpPathDao.insert(aip);
						if(aip==null){
							appABasicInformationDao.deleteById(code.getId());
							appBOccupationalDao.deleteById(code2.getId());
							appCIncomeAndLiabilityDao.deleteById(code3.getId());
							appDContactInformationDao.deleteById(code.getId());
							if(code.getWhetherOrNot().equals("2")){
								appEBorrowerInformationDao.deleteById(code5.getId());
							}
							return new ResponseData(false,"false");
						}
					}
				}
				if(code.getFileg() !=null && code.getFileg().size()>0){
					for(AppIImpPath aip:code.getFileg()){
						aip.setAppAId(code.getId());
						aip.setImpType("1");
						EntityUtils.initEntity(aip, session);
						appIImpPathDao.insert(aip);
						if(aip==null){
							appABasicInformationDao.deleteById(code.getId());
							appBOccupationalDao.deleteById(code2.getId());
							appCIncomeAndLiabilityDao.deleteById(code3.getId());
							appDContactInformationDao.deleteById(code.getId());
							if(code.getWhetherOrNot().equals("2")){
								appEBorrowerInformationDao.deleteById(code5.getId());
							}
							return new ResponseData(false,"false");
						}
					}
				}
				if(code.getFileh() !=null && code.getFileh().size()>0){
					for(AppIImpPath aip:code.getFileh()){
						aip.setAppAId(code.getId());
						aip.setImpType("1");
						EntityUtils.initEntity(aip, session);
						appIImpPathDao.insert(aip);
						if(aip==null){
							appABasicInformationDao.deleteById(code.getId());
							appBOccupationalDao.deleteById(code2.getId());
							appCIncomeAndLiabilityDao.deleteById(code3.getId());
							appDContactInformationDao.deleteById(code.getId());
							if(code.getWhetherOrNot().equals("2")){
								appEBorrowerInformationDao.deleteById(code5.getId());
							}
							return new ResponseData(false,"false");
						}
					}
				}
				if(code.getFilei() !=null && code.getFilei().size()>0){
					for(AppIImpPath aip:code.getFilei()){
						aip.setAppAId(code.getId());
						aip.setImpType("1");
						EntityUtils.initEntity(aip, session);
						appIImpPathDao.insert(aip);
						if(aip==null){
							appABasicInformationDao.deleteById(code.getId());
							appBOccupationalDao.deleteById(code2.getId());
							appCIncomeAndLiabilityDao.deleteById(code3.getId());
							appDContactInformationDao.deleteById(code.getId());
							if(code.getWhetherOrNot().equals("2")){
								appEBorrowerInformationDao.deleteById(code5.getId());
							}
							return new ResponseData(false,"false");
						}
					}
				}
			}
			return new ResponseData(true,"true",code);
		}catch(Exception e){
			return new ResponseData(false,"false");
		}
	}
	@Override
	public ResponseData upProduct(AppABasicInformation code,
			AppBOccupational code2, AppCIncomeAndLiability code3,
			ArrayList<AppDContactInformation> code4,
			AppEBorrowerInformation code5, AppFHouseProperty code6,
			AppGWorkInformation code7, AppHPolicyInformation code8) {
		try{
			AppABasicInformation one=appABasicInformationDao.selectById(code.getId());//放在前面免得数据被覆盖
			String del=one.getProductType();
			code.setDeleteFlag("N");
			EntityUtils.modifyEntity(code, session);
			appABasicInformationDao.insert(code);
			if(code==null){
				return new ResponseData(false,"false");
			}else{
				code2.setId(code.getAbo().getId());
				code2.setUnitName(code.getAbo().getUnitName());
				code2.setEntryTime(code.getAbo().getEntryTime());
				code2.setOfficePhone(code.getAbo().getOfficePhone());
				code2.setUnitAddressArea(code.getAbo().getUnitAddressArea());
				code2.setIndustryType(code.getAbo().getIndustryType());
				code2.setDepartment(code.getAbo().getDepartment());
				code2.setMonthlyPayday(code.getAbo().getMonthlyPayday());
				code2.setDeleteFlag("N");
				code2.setAppAId(code.getId());
				EntityUtils.modifyEntity(code2, session);
				appBOccupationalDao.insert(code2);
				if(code2==null){
					return new ResponseData(false,"false");
				}
				code3.setId(code.getAcial().getId());
				code3.setMonthlyIncome(code.getAcial().getMonthlyIncome());
				code3.setOtherMonthlyIncome(code.getAcial().getOtherMonthlyIncome());
				code3.setSupportNumber(code.getAcial().getSupportNumber());
				code3.setFamilyDebt(code.getAcial().getFamilyDebt());
				code3.setHousingLoan(code.getAcial().getHousingLoan());
				code3.setFixedExpenditure(code.getAcial().getFixedExpenditure());
				code3.setOrganizationName(code.getAcial().getOrganizationName());
				code3.setAmountOfMoney(code.getAcial().getAmountOfMoney());
				code3.setDeleteFlag("N");
				code3.setAppAId(code.getId());
				EntityUtils.modifyEntity(code3, session);
				appCIncomeAndLiabilityDao.insert(code3);
				if(code3==null){
					return new ResponseData(false,"false");
				}
				List<AppDContactInformation> adci=code.getAdci();
				for(AppDContactInformation adci2:adci){
					adci2.setDeleteFlag("N");
					adci2.setAppAId(code.getId());
					EntityUtils.modifyEntity(adci2, session);
					appDContactInformationDao.insert(adci2);
					if(adci2==null){
						return new ResponseData(false,"false");
					}
				}
				if(code.getWhetherOrNot().equals("2")){
					code5.setId(code.getAebi().getId());
					code5.setBoName(code.getAebi().getBoName());
					code5.setUnitName(code.getAebi().getUnitName());
					code5.setEntryTime(code.getAebi().getEntryTime());
					code5.setOfficePhone(code.getAebi().getOfficePhone());
					code5.seteAddressArea(code.getAebi().geteAddressArea());
					code5.setDeleteFlag("N");
					code5.setAppAId(code.getId());
					EntityUtils.modifyEntity(code5, session);
					appEBorrowerInformationDao.insert(code5);
					if(code5==null){
						return new ResponseData(false,"false");
					}
				}
				if(code.getProductType().equals("1") || code.getProductType().equals("3")){
					code6.setId(code.getAfhp().getId());
					code6.setReimbursementAmount(code.getAfhp().getReimbursementAmount());
					code6.setPurchaseTimeYear(code.getAfhp().getPurchaseTimeYear());
					code6.setPurchaseTimeMonth(code.getAfhp().getPurchaseTimeMonth());
					code6.setPurchasePrice(code.getAfhp().getPurchasePrice());
					code6.setArea(code.getAfhp().getArea());
					code6.setDeleteFlag("N");
					code6.setAppAId(code.getId());
					EntityUtils.modifyEntity(code6, session);
					appFHousePropertyDao.insert(code6);
					if(code6==null){
						return new ResponseData(false,"false");
					}
				}
				if(code.getProductType().equals("2") || code.getProductType().equals("5")){
					code7.setId(code.getAgwi().getId());
					code7.setAcDeposit(code.getAgwi().getAcDeposit());
					code7.setAcDepositLength(code.getAgwi().getAcDepositLength());
					code7.setAcFundAccount(code.getAgwi().getAcFundAccount());
					code7.setSoDeposit(code.getAgwi().getSoDeposit());
					code7.setAcDepositLength(code.getAgwi().getAcDepositLength());
					code7.setDeleteFlag("N");
					code7.setAppAId(code.getId());
					EntityUtils.modifyEntity(code7, session);
					appGWorkInformationDao.insert(code7);
					if(code7==null){
						return new ResponseData(false,"false");
					}
				}
				if(code.getProductType().equals("4")){
					code8.setId(code.getAhpi().getId());
					code8.setInsuranceCompany(code.getAhpi().getInsuranceCompany());
					code8.setEffectiveDate(code.getAhpi().getEffectiveDate());
					code8.setYears(code.getAhpi().getYears());
					code8.setRegularPremium(code.getAhpi().getRegularPremium());
					code8.setTotalAmountInsured(code.getAhpi().getTotalAmountInsured());
					code8.setDeleteFlag("N");
					code8.setAppAId(code.getId());
					EntityUtils.modifyEntity(code8, session);
					appHPolicyInformationDao.insert(code8);
					if(code8==null){
						return new ResponseData(false,"false");
					}
				}
			}
				if((code.getProductType().equals("1") || code.getProductType().equals("3"))
			   && !(del.equals("1") || del.equals("3"))){
					if(code.getAgwi().getId() !=null){
						appGWorkInformationDao.deleteById(code.getAgwi().getId());
					}
					if(code.getAhpi().getId() !=null){
						appHPolicyInformationDao.deleteById(code.getAhpi().getId());
					}
					if(code.getWhetherOrNot().equals("2")){
						appEBorrowerInformationDao.deleteById(code.getAebi().getId());
					}
				}else if((code.getProductType().equals("2") || code.getProductType().equals("5"))
						   && !(del.equals("2") || del.equals("5"))){
					if(code.getAfhp().getId() !=null){
						appFHousePropertyDao.deleteById(code.getAfhp().getId());
					}
					if(code.getAhpi().getId() !=null){
						appHPolicyInformationDao.deleteById(code.getAhpi().getId());
					}
					if(code.getWhetherOrNot().equals("2")){
						appEBorrowerInformationDao.deleteById(code.getAebi().getId());
					}
				}else if(code.getProductType().equals("4")&& !del.equals("4")){
					if(code.getAfhp().getId() !=null){
						appFHousePropertyDao.deleteById(code.getAfhp().getId());
					}
					if(code.getAgwi().getId() !=null){
						appGWorkInformationDao.deleteById(code.getAgwi().getId());
					}
					if(code.getWhetherOrNot().equals("2")){
						appEBorrowerInformationDao.deleteById(code.getAebi().getId());
					}
				}
				if(code.getFilea() !=null && code.getFilea().size()>0){
					for(AppIImpPath aip:code.getFilea()){
						aip.setAppAId(code.getId());
						aip.setImpType("1");
						EntityUtils.modifyEntity(aip, session);
						appIImpPathDao.insert(aip);
						if(aip==null){
							appABasicInformationDao.deleteById(code.getId());
							appBOccupationalDao.deleteById(code2.getId());
							appCIncomeAndLiabilityDao.deleteById(code3.getId());
							appDContactInformationDao.deleteById(code.getId());
							if(code.getWhetherOrNot().equals("2")){
								appEBorrowerInformationDao.deleteById(code5.getId());
							}
							return new ResponseData(false,"false");
						}
					}
				}
				if(code.getFileb() !=null && code.getFileb().size()>0){
					for(AppIImpPath aip:code.getFileb()){
						aip.setAppAId(code.getId());
						aip.setImpType("1");
						EntityUtils.modifyEntity(aip, session);
						appIImpPathDao.insert(aip);
						if(aip==null){
							appABasicInformationDao.deleteById(code.getId());
							appBOccupationalDao.deleteById(code2.getId());
							appCIncomeAndLiabilityDao.deleteById(code3.getId());
							appDContactInformationDao.deleteById(code.getId());
							if(code.getWhetherOrNot().equals("2")){
								appEBorrowerInformationDao.deleteById(code5.getId());
							}
							return new ResponseData(false,"false");
						}
					}
				}
				if(code.getFilec() !=null && code.getFilec().size()>0){
					for(AppIImpPath aip:code.getFilec()){
						aip.setAppAId(code.getId());
						aip.setImpType("1");
						EntityUtils.modifyEntity(aip, session);
						appIImpPathDao.insert(aip);
						if(aip==null){
							appABasicInformationDao.deleteById(code.getId());
							appBOccupationalDao.deleteById(code2.getId());
							appCIncomeAndLiabilityDao.deleteById(code3.getId());
							appDContactInformationDao.deleteById(code.getId());
							if(code.getWhetherOrNot().equals("2")){
								appEBorrowerInformationDao.deleteById(code5.getId());
							}
							return new ResponseData(false,"false");
						}
					}
				}
				if(code.getFiled() !=null && code.getFiled().size()>0){
					for(AppIImpPath aip:code.getFiled()){
						aip.setAppAId(code.getId());
						aip.setImpType("1");
						EntityUtils.modifyEntity(aip, session);
						appIImpPathDao.insert(aip);
						if(aip==null){
							appABasicInformationDao.deleteById(code.getId());
							appBOccupationalDao.deleteById(code2.getId());
							appCIncomeAndLiabilityDao.deleteById(code3.getId());
							appDContactInformationDao.deleteById(code.getId());
							if(code.getWhetherOrNot().equals("2")){
								appEBorrowerInformationDao.deleteById(code5.getId());
							}
							return new ResponseData(false,"false");
						}
					}
				}
				if(code.getFilee() !=null && code.getFilee().size()>0){
					for(AppIImpPath aip:code.getFilee()){
						aip.setAppAId(code.getId());
						aip.setImpType("1");
						EntityUtils.modifyEntity(aip, session);
						appIImpPathDao.insert(aip);
						if(aip==null){
							appABasicInformationDao.deleteById(code.getId());
							appBOccupationalDao.deleteById(code2.getId());
							appCIncomeAndLiabilityDao.deleteById(code3.getId());
							appDContactInformationDao.deleteById(code.getId());
							if(code.getWhetherOrNot().equals("2")){
								appEBorrowerInformationDao.deleteById(code5.getId());
							}
							return new ResponseData(false,"false");
						}
					}
				}
				if(code.getFilef() !=null && code.getFilef().size()>0){
					for(AppIImpPath aip:code.getFilef()){
						aip.setAppAId(code.getId());
						aip.setImpType("1");
						EntityUtils.modifyEntity(aip, session);
						appIImpPathDao.insert(aip);
						if(aip==null){
							appABasicInformationDao.deleteById(code.getId());
							appBOccupationalDao.deleteById(code2.getId());
							appCIncomeAndLiabilityDao.deleteById(code3.getId());
							appDContactInformationDao.deleteById(code.getId());
							if(code.getWhetherOrNot().equals("2")){
								appEBorrowerInformationDao.deleteById(code5.getId());
							}
							return new ResponseData(false,"false");
						}
					}
				}
				if(code.getFileg() !=null && code.getFileg().size()>0){
					for(AppIImpPath aip:code.getFileg()){
						aip.setAppAId(code.getId());
						aip.setImpType("1");
						EntityUtils.modifyEntity(aip, session);
						appIImpPathDao.insert(aip);
						if(aip==null){
							appABasicInformationDao.deleteById(code.getId());
							appBOccupationalDao.deleteById(code2.getId());
							appCIncomeAndLiabilityDao.deleteById(code3.getId());
							appDContactInformationDao.deleteById(code.getId());
							if(code.getWhetherOrNot().equals("2")){
								appEBorrowerInformationDao.deleteById(code5.getId());
							}
							return new ResponseData(false,"false");
						}
					}
				}
				if(code.getFileh() !=null && code.getFileh().size()>0){
					for(AppIImpPath aip:code.getFileh()){
						aip.setAppAId(code.getId());
						aip.setImpType("1");
						EntityUtils.modifyEntity(aip, session);
						appIImpPathDao.insert(aip);
						if(aip==null){
							appABasicInformationDao.deleteById(code.getId());
							appBOccupationalDao.deleteById(code2.getId());
							appCIncomeAndLiabilityDao.deleteById(code3.getId());
							appDContactInformationDao.deleteById(code.getId());
							if(code.getWhetherOrNot().equals("2")){
								appEBorrowerInformationDao.deleteById(code5.getId());
							}
							return new ResponseData(false,"false");
						}
					}
				}
				if(code.getFilei() !=null && code.getFilei().size()>0){
					for(AppIImpPath aip:code.getFilei()){
						aip.setAppAId(code.getId());
						aip.setImpType("1");
						EntityUtils.modifyEntity(aip, session);
						appIImpPathDao.insert(aip);
						if(aip==null){
							appABasicInformationDao.deleteById(code.getId());
							appBOccupationalDao.deleteById(code2.getId());
							appCIncomeAndLiabilityDao.deleteById(code3.getId());
							appDContactInformationDao.deleteById(code.getId());
							if(code.getWhetherOrNot().equals("2")){
								appEBorrowerInformationDao.deleteById(code5.getId());
							}
							return new ResponseData(false,"false");
						}
					}
				}
				if(code.getAip() !=null && code.getAip().size()>0){
					for(AppIImpPath aip:code.getAip()){
						if(aip !=null && aip.getDeleteFlag().equals("Y")){
							appIImpPathDao.deleteById(aip.getId());;
						}
					}
				}
			return new ResponseData(true,"true",code);
		}catch(Exception e){
			return new ResponseData(false,"false");
		}
	}
	@Override
	public ResponseData upAppABasicInformation(AppABasicInformation code) {
		try{
			EntityUtils.modifyEntity(code, session);
			appABasicInformationDao.insert(code);
			return new ResponseData(true,"true",code);
		}catch(Exception e){
			return new ResponseData(false,"false");
		}
	}

}
